package cn.enilu.flash.api.controller.cust;

import cn.enilu.flash.bean.entity.cust.CustHouseRef;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.enums.body.State;
import cn.enilu.flash.service.cust.CustHouseRefService;

import cn.enilu.flash.bean.core.BussinessLog;
import cn.enilu.flash.bean.constant.factory.PageFactory;
import cn.enilu.flash.bean.dictmap.CommonDict;
import cn.enilu.flash.bean.enumeration.BizExceptionEnum;
import cn.enilu.flash.bean.exception.GunsException;
import cn.enilu.flash.bean.vo.front.Rets;

import cn.enilu.flash.utils.Maps;
import cn.enilu.flash.utils.ToolUtil;
import cn.enilu.flash.utils.factory.Page;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/custhouseref")
public class CustHouseRefController {
	private  Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private CustHouseRefService custHouseRefService;

	@RequestMapping(value = "/list",method = RequestMethod.GET)
	public Object list() {
	Page<CustHouseRef> page = new PageFactory<CustHouseRef>().defaultPage();
		page = custHouseRefService.queryPage(page);
		return Rets.success(page);
	}
	@RequestMapping(method = RequestMethod.POST)
	@BussinessLog(value = "编辑客户房间关联", key = "name",dict= CommonDict.class)
	public Object save(@ModelAttribute CustHouseRef custHouseRef){
		if(custHouseRef.getId()==null){
			custHouseRefService.insert(custHouseRef);
		}else {
			custHouseRefService.update(custHouseRef);
		}
		return Rets.success();
	}
	@RequestMapping(method = RequestMethod.DELETE)
	@BussinessLog(value = "删除客户房间关联", key = "id",dict= CommonDict.class)
	public Object remove(Long id){
		if (ToolUtil.isEmpty(id)) {
			throw new GunsException(BizExceptionEnum.REQUEST_NULL);
		}
		custHouseRefService.delete(id);
		return Rets.success();
	}

	@RequestMapping(value = "/options/{communityId}",method = RequestMethod.GET)
	public Object options(@PathVariable("communityId") Long communityId){
		List<SearchFilter> sfs = new ArrayList<>();
		SearchFilter sf = SearchFilter.build("communityId", SearchFilter.Operator.EQ, communityId);
		sfs.add(sf);
		return Rets.success(custHouseRefService.queryAll(sf));
	}
}